package com.example.permission.myjbm.model;

import android.os.Handler;
import android.widget.ListView;
import android.widget.TextView;

import com.example.permission.myjbm.dao.BaseObj;
import com.example.permission.myjbm.net.ReleaseNet;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

/**
 * 礼券model
 * Created by JBMhaier on 2017/3/14.
 */

public class CertificateModel extends BaseObj {
    private final ReleaseNet net;
    private int page;

    public CertificateModel(TextView headerRight, TextView headerTitle, Handler handler){
        super(headerRight, headerTitle, "礼券中心", null);
        net=new ReleaseNet(handler);
        page=0;
    }

    public ReleaseNet getNet() {
        return net;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public void addNet(){
        net.getDiajinList(1,page);
    }

    public void setListener(  PullToRefreshListView certificatePull){
        certificatePull.setOnLastItemVisibleListener(new PullToRefreshBase.OnLastItemVisibleListener() {
            @Override
            public void onLastItemVisible() {
                page+=10;
                addNet();
            }
        });
        certificatePull.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
                page=0;
                addNet();
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
                page+=10;
                addNet();
            }
        });



    }


}
